
import CardDatasJson from "./card-datas-json.js";
import { isHasOwnProperty } from "@/utils/public.js";
import TooltipsData from "@/views/card/js/data/tooltipsData/tooltips-data.js";



/** CardTypeDatas
 * [CardTypeDatas card全部类型 以及 数据结构]
 * @type {Object}
 * classify : Card_Button / Card_Comb / Card_Disable/    ...其他都归 Card_Other
 */
export const CardTypeDatas = {
  CARD_4: {
    data: CardDatasJson.CARD_4,
    type: 'CARD_4',
    text: '标题 (4)',
    icon: 'jy-icon-contact',
    cid: 4004,
    isProduction: true
  },
  CARD_7: {
    data: CardDatasJson.CARD_7,
    type: 'CARD_7',
    text: '纯文本 (7)',
    icon: 'jy-icon-contact',
    cid: 4007,
    isProduction: true
  },
  CARD_8: {
    data: CardDatasJson.CARD_8,
    type: 'CARD_8',
    text: '左图右文混排 (8)',
    icon: 'jy-icon-contact',
    cid: 4008,
    isProduction: true
  },
  CARD_9: {
    data: CardDatasJson.CARD_9,
    type: 'CARD_9',
    text: '微博Card (9)',
    icon: 'jy-icon-contact',
    cid: 4009,
    isProduction: true
  },
  CARD_10: {
    data: CardDatasJson.CARD_10,
    type: 'CARD_10',
    text: '用户 (10)',
    icon: 'jy-icon-contact',
    cid: 4010,
    isProduction: true
  },
  CARD_17: {
    data: CardDatasJson.CARD_17,
    type: 'CARD_17',
    text: '卡片式多文字 (17)',
    icon: 'jy-icon-contact',
    cid: 4017,
    isProduction: true
  },
  CARD_27: {
    data: CardDatasJson.CARD_27,
    type: 'CARD_27',
    text: '标题/图/描述/按钮 (27)',
    icon: 'jy-icon-contact',
    cid: 4027,
    isProduction: true
  },
  CARD_28: {
    data: CardDatasJson.CARD_28,
    type: 'CARD_28',
    text: '单头像+两个字段 (28)',
    icon: 'jy-icon-contact',
    cid: 4028,
    isProduction: true
  },
  CARD_22: {
    data: CardDatasJson.CARD_22,
    type: 'CARD_22',
    text: '多图轮播 (22)',
    icon: 'jy-icon-contact',
    cid: 4022,
    isProduction: true
  },
  // CARD_24: {
  //   data: CardDatasJson.CARD_24,
  //   type: 'CARD_24',
  //   text: 'buzhidao (24)',
  //   icon: 'jy-icon-contact',
  //   cid: 4024,
  //   isProduction: true
  // },
  CARD_31: {
    data: CardDatasJson.CARD_31,
    type: 'CARD_31',
    text: '搜索框 (31)',
    icon: 'jy-icon-contact',
    cid: 4031,
    isProduction: true
  },
  CARD_35: {
    data: CardDatasJson.CARD_35,
    type: 'CARD_35',
    text: '宫格图片 (35)',
    icon: 'jy-icon-contact',
    cid: 4035,
    isProduction: true
  },
  CARD_42: {
    data: CardDatasJson.CARD_42,
    type: 'CARD_42',
    text: '标题 (42)',
    icon: 'jy-icon-contact',
    cid: 4042,
    isProduction: true
  },
  CARD_52: {
    data: CardDatasJson.CARD_52,
    type: 'CARD_52',
    text: '双图商业化 (52)',
    icon: 'jy-icon-contact',
    cid: 4052,
    isProduction: true
  },
  CARD_59: {
    data: CardDatasJson.CARD_59,
    type: 'CARD_59',
    text: '随手拍 (59)',
    icon: 'jy-icon-contact',
    cid: 4059,
    isProduction: true,
    // bIsDisabled: true
  },
  CARD_137: {
    data: CardDatasJson.CARD_137,
    type: 'CARD_137',
    text: 'Tag card (137)',
    icon: 'jy-icon-contact',
    cid: 40137,
    isProduction: true,
    // bIsDisabled: true
  },
  CARD_113: {
    data: CardDatasJson.CARD_113,
    type: 'CARD_113',
    text: '微博故事 (113)',
    icon: 'jy-icon-contact',
    cid: 40113,
    isProduction: true,
    bIsDisabled: true
  },
  CARD_121: {
    data: CardDatasJson.CARD_121,
    type: 'CARD_121',
    text: '121 (121)',
    icon: 'jy-icon-contact',
    cid: 40121,
    isProduction: true,
    bIsDisabled: true
  },
  CARD_158: {
    data: CardDatasJson.CARD_158,
    type: 'CARD_158',
    text: '新增瀑布流Card (158)',
    icon: 'jy-icon-contact',
    cid: 40158,
    isProduction: true,
    bIsDisabled: true
  },
  CARD_148: {
    data: CardDatasJson.CARD_148,
    type: 'CARD_148',
    text: '催更Card (148)',
    icon: 'jy-icon-contact',
    cid: 40148,
    isProduction: true,
    bIsDisabled: true
  },
  CARD_2003: {
    data: CardDatasJson.CARD_2003,
    type: 'CARD_2003',
    text: '动态数字 (2003)',
    icon: 'jy-icon-contact',
    cid: 402003,
    isProduction: true,
    // bIsDisabled: true
  },
  CARD_101: {
    data: CardDatasJson.CARD_101,
    type: 'CARD_101',
    text: '发现页标题 (101)',
    tips: TooltipsData.CARD_101[1] + TooltipsData.CARD_101[0],
    icon: 'jy-icon-contact',
    cid: 40101,
    isProduction: true,
    // bIsDisabled: true
  },
  CARD_199: {
    data: CardDatasJson.CARD_199,
    type: 'CARD_199',
    text: '实况讨论 (199)',
    icon: 'jy-icon-contact',
    cid: 40199,
    isProduction: false,
    // bIsDisabled: true
  },
  CARD_166: {
    data: CardDatasJson.CARD_166,
    type: 'CARD_166',
    text: '福牛card (166)',
    icon: 'jy-icon-contact',
    cid: 40166,
    isProduction: true,
    // bIsDisabled: true
  },

  /* Card_Comb */
  CARD_11: {
    classify: 'Card_Comb',
    classifyName: '组合 Card',
    data: CardDatasJson.CARD_11,
    type: 'CARD_11',
    text: '组合Card (11)',
    icon: 'jy-icon-contact',
    cid: 4011,
    isProduction: true
  },

  /* Card_Button */
  CARD_6: {
    classify: 'Card_Button',
    classifyName: '按钮 Card',
    data: CardDatasJson.CARD_6,
    type: 'CARD_6',
    text: '按钮card (6)',
    icon: 'jy-icon-contact',
    cid: 4006,
    isProduction: true,
    // bIsDisabled: true
  },
  CARD_16: {
    classify: 'Card_Button',
    classifyName: '按钮 Card',
    data: CardDatasJson.CARD_16,
    type: 'CARD_16',
    text: '卡片式双按钮 (16)',
    icon: 'jy-icon-contact',
    cid: 4016,
    isProduction: true,
    // bIsDisabled: true
  },
  CARD_19: {
    classify: 'Card_Button',
    classifyName: '按钮 Card',
    data: CardDatasJson.CARD_19,
    type: 'CARD_19',
    text: '卡片式功能按钮 (19)',
    icon: 'jy-icon-contact',
    cid: 4019,
    isProduction: true,
    // bIsDisabled: true
  },

  /* Card_Live */
  CARD_81: {
    classify: 'Card_Live',
    classifyName: '直播 Card',
    data: CardDatasJson.CARD_81,
    type: 'CARD_81',
    text: '单个直播card (81)',
    icon: 'jy-icon-contact',
    cid: 4081,
    isProduction: true,
    // bIsDisabled: true
  },
  CARD_88: {
    classify: 'Card_Live',
    classifyName: '直播 Card',
    data: CardDatasJson.CARD_88,
    type: 'CARD_88',
    text: '双排直播card (88)',
    icon: 'jy-icon-contact',
    cid: 4088,
    isProduction: true,
    // bIsDisabled: true
  },

  /* Card_Video */
  CARD_89: {
    classify: 'Card_Video',
    classifyName: '视频 Card',
    data: CardDatasJson.CARD_89,
    type: 'CARD_89',
    text: '新版视频card (89)',
    icon: 'jy-icon-contact',
    cid: 4089,
    isProduction: true,
    // bIsDisabled: true
  },
  CARD_115: {
    classify: 'Card_Video',
    classifyName: '视频 Card',
    data: CardDatasJson.CARD_115,
    type: 'CARD_115',
    text: '活动视频card (115)',
    icon: 'jy-icon-contact',
    cid: 40115,
    isProduction: true,
    // bIsDisabled: true
  },
  CARD_124: {
    classify: 'Card_Video',
    classifyName: '视频 Card',
    data: CardDatasJson.CARD_124,
    type: 'CARD_124',
    text: '视频榜单轮播card (124)',
    icon: 'jy-icon-contact',
    cid: 40124,
    isProduction: true,
    // bIsDisabled: true
  },


  /* Card_Find 发现页横划 */
  CARD_86: {
    classify: 'Card_Find',
    classifyName: '发现页横滑 Card',
    data: CardDatasJson.CARD_86,
    type: 'CARD_86',
    text: '发现页横滑card (86)',
    icon: 'jy-icon-contact',
    cid: 4086,
    isProduction: true,
    // bIsDisabled: true
  },
  CARD_80: {
    classify: 'Card_Find',
    classifyName: '发现页横滑 Card',
    data: CardDatasJson.CARD_80,
    type: 'CARD_80',
    text: '文章趋势card (80)',
    icon: 'jy-icon-contact',
    cid: 4080,
    isProduction: true,
    // bIsDisabled: true
  },
  CARD_87: {
    classify: 'Card_Find',
    classifyName: '发现页横滑 Card',
    data: CardDatasJson.CARD_87,
    type: 'CARD_87',
    text: '发现页横滑item (87)',
    icon: 'jy-icon-contact',
    cid: 4087,
    isProduction: true,
    // bIsDisabled: true
  },
  CARD_128: {
    classify: 'Card_Find',
    classifyName: '发现页横滑 Card',
    data: CardDatasJson.CARD_128,
    type: 'CARD_128',
    text: '微博故事趋势卡片 (128)',
    icon: 'jy-icon-contact',
    cid: 40128,
    isProduction: true,
    bIsDisabled: true
  },
  CARD_160: {
    classify: 'Card_Find',
    classifyName: '发现页横滑 Card',
    data: CardDatasJson.CARD_160,
    type: 'CARD_160',
    text: '天猫双十一卡片 (160)',
    icon: 'jy-icon-contact',
    cid: 40160,
    isProduction: true,
    bIsDisabled: true
  },

  /* Card_Banner 轮播banner */
  CARD_118: {
    classify: 'Card_Banner',
    classifyName: '渐变效果 Card',
    data: CardDatasJson.CARD_118,
    type: 'CARD_118',
    text: '渐变效果的card (118)',
    icon: 'jy-icon-contact',
    cid: 40118,
    isProduction: true,
    // bIsDisabled: true
  },
  CARD_119: {
    classify: 'Card_Banner',
    classifyName: '渐变效果 Card',
    data: CardDatasJson.CARD_119,
    type: 'CARD_119',
    text: '三拼card (119)',
    icon: 'jy-icon-contact',
    cid: 40119,
    isProduction: true,
    // bIsDisabled: true
  },

  /* Card_PK */
  CARD_2001: {
    classify: 'Card_PK',
    classifyName: 'PK Card',
    data: CardDatasJson.CARD_2001,
    type: 'CARD_2001',
    text: 'PK (2001)',
    icon: 'jy-icon-contact',
    cid: 402001,
    isProduction: true,
    // bIsDisabled: true
  },

  /* CARD_JY */
  CARD_JY0001: {
    classify: 'Card_JY',
    classifyName: '业务 Card',
    data: CardDatasJson.CARD_JY0001,
    type: 'CARD_JY0001',
    text: '业务 (JY0001)',
    icon: 'jy-icon-contact',
    cid: '40JY0001',
    isProduction: true,
    // bIsDisabled: true
  },
  CARD_JY0002: {
    classify: 'Card_JY',
    classifyName: '业务 Card',
    data: CardDatasJson.CARD_JY0002,
    type: 'CARD_JY0002',
    text: '业务 (JY0002)',
    icon: 'jy-icon-contact',
    cid: '40JY0002',
    isProduction: true,
    // bIsDisabled: true
  },
  CARD_JY0005216: {
    classify: 'Card_JY',
    classifyName: '业务 Card',
    data: CardDatasJson.CARD_JY0005216,
    type: 'CARD_JY0005216',
    text: '业务 52+16 (JY0005216)',
    icon: 'jy-icon-contact',
    cid: '40JY0005216',
    isProduction: true,
    bIsDisabled: true
  },
};

/** _getAllCardTypes
 * [_getAllCardTypes 获取 card 类型 以及 描述 的方法]
 * @param  {[type]} cardTypeDatas [description]
 *   {[type]}               [description]
 */
export const _getAllCardTypes = (reg) => {
  // card type lists
  const arrCardTypes = Object.keys(CardTypeDatas);
  let CardTypeLists = [];
  let tempCardTypeLists = [];

  // 1. 造 tempCardTypeLists => tempCardTypeLists[ 'Card_Disable': [], 'Card_Other': [] ]
  for( let index = 0; index < arrCardTypes.length; index++ ) {
    const item = arrCardTypes[index];
    if( reg && !reg.test( CardTypeDatas[item].type ) ) continue;

    const newItem = {
      classify: CardTypeDatas[item].classify,
      classifyName: CardTypeDatas[item].classifyName,
      type: CardTypeDatas[item].type,
      text: CardTypeDatas[item].text,
      icon: CardTypeDatas[item].icon,
      cid: CardTypeDatas[item].cid,
      isProduction: CardTypeDatas[item].isProduction,
      bIsDisabled: CardTypeDatas[item].bIsDisabled,
    };

    if( CardTypeDatas[item].classify && !CardTypeDatas[item].bIsDisabled ) {
      if( !isHasOwnProperty( tempCardTypeLists, CardTypeDatas[item].classify ) )
        tempCardTypeLists[CardTypeDatas[item].classify] = [];
      tempCardTypeLists[CardTypeDatas[item].classify].push( newItem );
    }
    else if( CardTypeDatas[item].bIsDisabled ) {
      if( !isHasOwnProperty( tempCardTypeLists, 'Card_Disable' ) )
        tempCardTypeLists['Card_Disable'] = [];
      tempCardTypeLists['Card_Disable'].push( newItem );
    }
    else {
      if( !isHasOwnProperty( tempCardTypeLists, 'Card_Other' ) )
        tempCardTypeLists['Card_Other'] = [];
      tempCardTypeLists['Card_Other'].push( newItem );
    }
  }

  // 2. 造 CardTypeLists
  for(let key in tempCardTypeLists) {
    if( !tempCardTypeLists[key] || tempCardTypeLists[key].length <= 0 ) continue;
    let objTempCardClassify = {
      title: '',
      classify: key,
      lists: tempCardTypeLists[key],
    };
    if( key == 'Card_Disable' ) objTempCardClassify.title = '测试 Card';
    else if( key == 'Card_Other' ) objTempCardClassify.title = 'Card';
    else objTempCardClassify.title = tempCardTypeLists[key][0].classifyName;
    CardTypeLists.push(objTempCardClassify);
  }

  // 3. 重新排序 CardTypeLists => Card_Other:Infinity > Card_xxx >  Card_Disable:-Infinity
  CardTypeLists.sort((f, s) => {
    let a = f.classify == 'Card_Other' ?
      Infinity :
      ( f.classify == 'Card_Disable' ? -Infinity : f.classify.length );
    let b = s.classify == 'Card_Other' ?
      Infinity :
      ( s.classify == 'Card_Disable' ? -Infinity : s.classify.length );
    return a > b ? -1 : 1;
  });

  return CardTypeLists;
};
